<template>
  <d2-container>
    <div class="d2-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>园区管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-form :inline="true" class="SearchForm" label-width="80px">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="园区名称">
            <el-input
              placeholder="请输入"
              type="text"
              v-model.trim="searchForm.gardenName"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="园区类型">
            <el-select v-model="searchForm.gardenType">
              <el-option label="园区" :value="1"></el-option>
              <el-option label="写字楼" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="上架状态">
            <el-select v-model="searchForm.shelfStatus">
              <el-option label="未上架" :value="0"></el-option>
              <el-option label="上架" :value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="地址(省)">
            <el-input
              placeholder="请输入"
              type="text"
              v-model.trim="searchForm.province"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="地址(市)">
            <el-input
              placeholder="请输入"
              type="text"
              v-model.trim="searchForm.city"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="地址(县/区)">
            <el-input
              placeholder="请输入"
              type="text"
              v-model.trim="searchForm.county"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="详细地址">
            <el-input
              placeholder="请输入"
              type="text"
              v-model.trim="searchForm.address"
              clearable
            ></el-input>
          </el-form-item>
        </el-col>

        <el-button type="primary" @click="search()" icon="el-icon-search"
          >查询</el-button
        >
        <el-button type="danger" icon="el-icon-refresh" @click="reset"
          >重置</el-button
        >
        <el-form-item style="margin-left:10px">
          <router-link to="/garden/add">
            <el-button type="success">新增园区</el-button>
          </router-link>
        </el-form-item>
      </el-row>
    </el-form>
    <el-table border :data="tableData.list">
      <el-table-column label="序号" align="center" prop="id"></el-table-column>
      <el-table-column
        label="园区名称"
        align="center"
        prop="gardenName"
      ></el-table-column>
      <el-table-column label="园区类型" align="center" prop="gardenType">
        <template slot-scope="scope">
          {{ ["", "园区", "写字楼"][scope.row.gardenType] }}
        </template></el-table-column
      >
      <el-table-column label="地址" align="center" prop="address">
        <template slot-scope="scope">
          {{ `${scope.row.province},${scope.row.city},${scope.row.county}` }}
        </template>
      </el-table-column>
      <el-table-column
        label="详细地址"
        align="center"
        prop="address"
      ></el-table-column>
      <el-table-column
        label="园区联系人姓名"
        align="center"
        prop="gardenContacts"
      ></el-table-column>
      <el-table-column
        label="园区联系方式"
        align="center"
        prop="gardenPhone"
      ></el-table-column>
      <el-table-column
        label="管理物业公司名称"
        align="center"
        prop="manageCompany"
      ></el-table-column>
      <el-table-column
        label="管理物业公司联系人"
        align="center"
        prop="manageName"
      ></el-table-column>
      <el-table-column
        label="物业联系方式"
        align="center"
        prop="phone"
      ></el-table-column>

      <el-table-column label="推荐状态" align="center">
        <template slot-scope="scope">
          {{ ["未推荐", "推荐"][scope.row.recommend] }}
        </template>
      </el-table-column>
      <el-table-column label="上架状态" align="center">
        <template slot-scope="scope">
          {{ ["未上架", "上架"][scope.row.shelfStatus] }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="`/garden/edit/${scope.row.id}`">
            <el-button type="text" class="margin-left">查看/编辑</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="search"
      @current-change="search"
      :current-page.sync="page"
      :page-sizes="[10, 25, 50, 100]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.total"
    ></el-pagination>
  </d2-container>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      searchForm: {},
      tableData: {
        list: [],
        total: 0,
      },
      page: 1,
      pageSize: 10,
    };
  },
  methods: {
    search() {
      let params = {
        pageNum: this.page,
        pageSize: this.pageSize,
        ...this.searchForm,
      };

      this.$axios.post("wxGarden/list", params).then((result) => {
        if (result) {
          this.tableData = {
            list: result.data.list,
            total: result.data.total,
          };
        } else {
          this.$message.error(result.data.msg);
        }
      });
    },
    reset() {
      this.searchForm = {};
      this.search();
    },
  },
  created() {
    this.search();
  },
};
</script>

<style scoped lang="scss">
</style>
